home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.19990422-19990725 / 000043_news@watsun.cc.columbia.edu _Fri May 7 20:17:18 1999.msg < prev    next >
Internet Message Format  |  2020-01-01  |  5KB

  1. Return-Path: <news@watsun.cc.columbia.edu>
  2. Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
  3.     by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id UAA14147
  4.     for <kermit.misc@watsun.cc.columbia.edu>; Fri, 7 May 1999 20:17:18 -0400 (EDT)
  5. Received: (from news@localhost)
  6.     by newsmaster.cc.columbia.edu (8.8.5/8.8.5) id UAA25732
  7.     for kermit.misc@watsun.cc.columbia.edu; Fri, 7 May 1999 20:12:08 -0400 (EDT)
  8. X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
  9. From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
  10. Subject: Re: scripting against curses
  11. Date: 8 May 1999 00:12:07 GMT
  12. Organization: Columbia University
  13. Message-ID: <7gvvgn$p41$1@newsmaster.cc.columbia.edu>
  14. To: kermit.misc@watsun.cc.columbia.edu
  15.  
  16. In article <7gvsrc$no6$1@samba.rahul.net>,  <dold@network.rahul.net> wrote:
  17. : I haven't even tried yet, so maybe this will be simple ;-)
  18. : I need to develop a script to replace some manual entries to the SMS-800
  19. : database.  I've done similar scripts, but this one is _very_ vt100-heavy.
  20. : I don't know if I can 'input' for a set of text.
  21. : Instead of a character string, like 8005551212, I get cursor position
  22. : escapes around each character, at least that's what it looks like in a log
  23. : session.
  24. : I've been doing the logging from a K95 session, but I want to script it
  25. : from ckermit 7, unix, and ignore the screen positioning stuff.
  26. : Does 'input' ignore escape sequences for the TERM type that kermit is
  27. : using, or am I going to have to look for the full string?
  28. No, INPUT sees all characters that come in (except NUL), so you would actually
  29. match against escape sequences.  I'd recommend you begin by finding out how
  30. to tell when the screen is completely painted.  Then:
  31.  
  32.   1. CLEAR INPUT
  33.        Clear the INPUT buffer (and the \v(input) variable).
  34.  
  35.   2. OUTPUT xxx
  36.        Where xxx is whatever you would type to make the thing put up
  37.        a screen.
  38.  
  39.   3. INPUT nn zzz
  40.        Where nn is an upper bound on the number of seconds to wait for the
  41.        screen to be completed, and zzz is some sequence you can use to
  42.        identify when the painting is complete.
  43.  
  44. At this point you have the whole screen in the \v(input) variable, or,
  45. more precisely, the sequence of characters that was sent to the terminal to
  46. make it paint the screen -- escape sequences and all.
  47.  
  48. Now you can use string functions to parse it, as in the "modemtest" sample
  49. script in our new script library:
  50.  
  51.   http://www.columbia.edu/kermit/ckscripts.html
  52.  
  53. Doing it this way ensures you don't lose stuff and it also frees you from
  54. dependence on the order in which the fields arrive.  Just search for the
  55. appropriate tag (which in this case might be a CUP escape sequence) and then
  56. extract the following string.  For example, suppose you're looking for a
  57. 10-digit phone number at cursor position [10,20] (row,column).  The escape
  58. sequence would be <ESC>[10;20H, so to extract the data you might do
  59. something like this (in C-Kermit 7.0 syntax)(*):
  60.  
  61.   .\%x ::= \findex(\27[10;20H,\v(input)) + 8  ; Find CUP[10,20]
  62.   .\%s := \fsubstr(\v(input),\%x,10)          ; Get 10 chars after it
  63.  
  64. If you were using Kermit 95, you could take advantage of its built-in
  65. HLLAPI-like "screen scraping" functions, which are used *after* the terminal
  66. emulator has formatted the screen.  In this case you could get the same
  67. effect with:
  68.  
  69.   \fscrstr(ny,nx,n1)
  70.     ny = integer.
  71.     nx = integer.
  72.     n1 = integer.
  73.   Returns string:
  74.     The string at Terminal-screen coordinates (nx,ny), length n1,
  75.     blanks included.  
  76.  
  77. In this case: .\%s := \fscrstr(20,10,10)
  78.  
  79. The screen-scraping approach is ex-post-facto; it is applied after the data
  80. arrived and treats the screen like a matrix of characters; in this case
  81. escape sequences are long-gone and irrelevant, and you don't reference the
  82. INPUT buffer at all.
  83.  
  84. In both cases, however, you need to know when it is safe to start looking,
  85. i.e. at what point the screen is completely painted.
  86.  
  87. (*) For those of you who have not looked at C-Kermit 7.0 yet, the new
  88. assignment operators look like:
  89.  
  90.  .<variablename> <operator> <value>
  91.  
  92. where:
  93.  
  94.   <variablename> can be any kind of variable
  95.  
  96.   <operator> is:
  97.  
  98.      =    To copy the <value> literally.
  99.      :=   To expand all variables in the value and then copy.
  100.      ::=  Like :=, but then treats the result as an arithmetic expression
  101.           and evalulates it.
  102.  
  103. So:
  104.  
  105.   .\%x ::= \findex(\27[10;20H,\v(input)) + 8
  106.  
  107. replaces \v(input) by the contents of the INPUT buffer, finds the position
  108. of "\27[10;20H" in it, adds 8 to it, and assigns the result to \%x.
  109.  
  110. Of course you can do the same in earlier Kermit versions, but the syntax is
  111. a bit more awkward:
  112.  
  113.   assign \%x \feval(\findex(\27[10;20H,\v(input))+8)
  114.  
  115. - Frank